package com.bbx.taxi.client.Task;

import android.app.Activity;
import android.content.Context;
import android.util.Log;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.passanger.BalanceBuild;
import com.bbx.api.sdk.model.passanger.PriceBuild;
import com.bbx.api.sdk.model.passanger.RechargeBuild;
import com.bbx.api.sdk.model.passanger.Return.Recharge;
import com.bbx.api.sdk.net.base.BaseNetwork;
import com.bbx.api.sdk.net.passeger.conn.BalanceNet;
import com.bbx.api.sdk.net.passeger.conn.PriceNet;
import com.bbx.api.sdk.net.passeger.conn.RechargeNet;
import com.bbx.api.util.LogUtils;
import com.bbx.taxi.client.Activity.Main.MainActivity;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Bean.Message.ObserverListener;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.pay.alipay.PayAlipay;
import com.bbx.taxi.client.pay.weixin.PayWeixin;

/**
 * 作者：严旭文 on 2016/12/30 10:02
 * 邮箱：420255048@qq.com
 *  充值
 */
public class MyRechargeTask extends BaseTask{
    public enum GATEWAY{
        weixin,alipay
    }
    public ObserverListener.DATA_TYPE TYPE= ObserverListener.DATA_TYPE.RECHARGE;
    RechargeBuild mRechargeBuild;
    private Activity context;
    private GATEWAY gateway;
    public MyRechargeTask(Activity context,GATEWAY gateway,String amount) {
        super(context);
        this.context=context;
        mRechargeBuild = new RechargeBuild(context);
        mRechargeBuild.uid= MyApplication.getInstance().getUid();
        mRechargeBuild.access_token= MyApplication.getInstance().getToken();
        mRechargeBuild.amount=amount;
        this.gateway=gateway;
        if(gateway==GATEWAY.weixin){
            mRechargeBuild.gateway="weixin";
        }else if(gateway==GATEWAY.alipay){
            mRechargeBuild.gateway="alipay";
        }
    }
    @Override
    public boolean isShow() {
        return true;
    }
    @Override
    public boolean isReturnString() {
        return false;
    }
    @Override
    public boolean condition() {
        // TODO Auto-generated method stub
        return true;
    }
    public void request() {
        setType(TYPE,mRechargeBuild);
    }
    @Override
    public void success(int status,Object object) {
        if(object!=null){
            Recharge mRecharge=(Recharge)object;
            if(mRecharge!=null){
            String data=mRecharge.getData();
            if(data!=null){
                if(gateway==GATEWAY.weixin){
                    PayWeixin mPayWeixin=new PayWeixin(context);
                    mPayWeixin.onRecharge(data);
                }else if(gateway==GATEWAY.alipay){
                    PayAlipay payalipay = new PayAlipay(context);
                    payalipay.onRecharge(mRecharge.getAlipay_sign(),mRecharge.getAlipay_sign_type(),data);
                }
              }
            }
        }
    }
    @Override
    public void failed(int status, String msg,String message) {
        ToastUtil.showToast(context,message);

    }
    @Override
    public BaseNetwork getBaseNetwork() {
        return new RechargeNet(context);
    }
}

